<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>申请表</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>


<style type="text/css">
table {
	border-right: 1px solid #00BB00;
	border-bottom: 1px solid #00BB00
}

table td {
	border-left: 1px solid #00BB00;
	border-top: 1px solid #00BB00
}
</style>

</head>

<body>
	<center>
		<a style="float: left" href="<%=basePath%>sign">申请资源</a><br> <a
			style="float: left" href="<%=basePath%>resourcelist">查看资源列表</a> 申请表.
		<br>
		<table>
			<tr>
				<td>申请时间</td>
				<td>资源名称</td>
				<c:if test="${!empty param.key }">
					<td>持有人</td>
				</c:if>
				<td>申请人</td>
				<td>申请理由</td>
				<td>申请状态</td>
				<c:if test="${!empty param.key }">
					<td>操作</td>
				</c:if>
				<td>拒绝原因</td>
			</tr>
			<c:forEach items="${list }" var="obj">
				<tr>
					<td>${obj.createDate }</td>
					<td>${obj.name }</td>
					<c:if test="${!empty param.key }">
						<td>${obj.holder }</td>
					</c:if>
					<td>${obj.signName  }</td>
					<td>${obj.signReason }</td>
					<td>${empty obj.signStatus?"空闲":obj.signStatus }</td>
					<c:if test="${!empty param.key }">
						<td>
						
							<c:if
								test="${empty obj.signStatus || obj.signStatus=='申请中'}">
								<a href="javascript:void(0);" class="passed"
									data-holder="${obj.signName  }" data-rejectReason=" "
									data-id="${obj.id }" data-signstatus="通过">通过</a>|
				    			<a href="javascript:void(0);" class="rejected"
									data-holder="${obj.holder  }"
									data-rejectreasonid="rejectReason${obj.id }"
									data-id="${obj.id }" data-signstatus="拒绝">拒绝</a>
							</c:if>
							
							<c:if
								test="${!empty obj.signStatus && obj.signStatus=='通过'}">
								<a href="javascript:void(0);" class="toBack"
									data-holder="仓库"
									data-id="${obj.id }" data-signstatus="已归还">归还</a>
							</c:if>
							
							
							
						</td>
					</c:if>

					<td><c:if
							test="${empty obj.signStatus || obj.signStatus=='申请中'}">
							<input id="rejectReason${obj.id }" name="rejectReason"
								value="${obj.rejectReason }">
						</c:if> <label value="">${obj.rejectReason }</label></td>
				</tr>
			</c:forEach>
		</table>
	</center>
</body>
<script type="text/javascript">
	var key = '${param.key}';
	$(".toBack").bind(
			"click",
			function() {
				$(this).unbind("click");
				var id = $(this).data("id");
				var signStatus = $(this).data("signstatus");
				var holder = $(this).data("holder");
				$.ajax({
							type : "POST",
							url : "/setSignStatus?key=" + key + "&id=" + id
									+ "&signStatus=" + signStatus + "&holder="+ holder,
							dataType : 'text',
							success : function(data) {
								alert(data);
								location.reload();
							}
						});
			});
	
	$(".passed").bind(
			"click",
			function() {
				$(this).unbind("click");
				var id = $(this).data("id");
				var signStatus = $(this).data("signstatus");
				var holder = $(this).data("holder");
				$
						.ajax({
							type : "POST",
							url : "/setSignStatus?key=" + key + "&id=" + id
									+ "&signStatus=" + signStatus + "&holder="
									+ holder,
							dataType : 'text',
							success : function(data) {
								alert(data);
								location.reload();
							}
						});
			});

	$(".rejected").bind(
			"click",
			function() {
				$(this).unbind("click");
				var id = $(this).data("id");
				var signStatus = $(this).data("signstatus");
				var holder = $(this).data("holder");
				var rejectReasonid = $(this).data("rejectreasonid");
				var rejectReason = $("#" + rejectReasonid).val();
				$.ajax({
					type : "POST",
					url : "/setSignStatus?key=" + key + "&id=" + id
							+ "&signStatus=" + signStatus + "&rejectReason="
							+ rejectReason + "&holder=" + holder,
					dataType : 'text',
					success : function(data) {
						alert(data);
						location.reload();
					}
				});
			});
</script>
</html>
